package com.thread.xxstudy;


import java.util.ArrayList;
import java.util.List;


/**
 * 等待所有线程执行完以后打印100000000000000
 */
public class JoinWati {

    int a ;
    class Call implements Runnable {
        @Override
        public void run() {
            System.out.println(++a);
        }
    }



    void join(){
        Call call = new Call();
        List<Thread> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(call);
            list.add(thread);
            thread.start();
        }

        //等待所有线程执行完
        list.forEach(t->{
            try {
                t.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        System.out.println("100000000000000");
    }

    /*public static void main(String[] args) {
        new JoinWati().join();
    }*/
}
